<template>
  <div>
    <h2>注册页面</h2>
    <table>
      <tr>
        <td>用户名</td>
        <td>
          <input type="text" v-model="state.Uname">
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="password" v-model="state.Upwd">
        </td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" value="注册" @click="Register"></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
  import router from '@/router';
import axios from 'axios';
import {reactive,toRefs} from 'vue'
  let data=reactive({
    state:{
      Uname:"",
      Upwd:""
    }
    })
    let {state}=toRefs(data);
    function Register()
    {
      
      axios({
        url:"http://localhost:57328/api/User/PostUserRegister",
        method:"post",
        data:state.value
      })
      .then(res=>{
        console.log(res);
        if(res.data.data>0)
      {
        alert("注册成功");
        router.push("/login")
      }
      else if(res.data.data==-1)
      {
        alert("用户账号不能重复");
        return;
      }
      })
      .catch(err=>{
        console.log(err);
      })
    }
</script>

<style scoped>

</style>